package Flap::App::Web::UserAgent;
use Flap qw/-b Flap::Object -m -r -s -w/;
use constant content_type => 'text/html';
use constant encoding => 'utf-8';
use constant view_suffix => '';

use constant HEAD5 => {
    'DoCoM' => 'Docomo',
    'KDDI-' => 'Au',
    'UP.Br' => 'Au',
    'J-PHO' => 'Softbank',
    'Vodaf' => 'Softbank',
    'SoftB' => 'Softbank',
};

sub detect {
    my($class, $c) = @_;
    my $ua = $c->req->user_agent || return undef;
    if($ua && length($ua) >= 5 && (my $d = $class->HEAD5->{substr($ua, 0, 5)})){
        return $d;
    }
    $ua =~ m%iPhone|iPod% ? 'IPhone' : undef;
}

sub new {
    my($class, $c) = @_;
    my $ua = $class->detect($c) || 'PC';
    $class->$ua->_new($c);
}

sub _new {
    my $ua = shift->_new_({c => shift});
    $ua->_weaken_($ua->{c});
    $ua;
}

1;
